package com.tj.test.sys.service.impl;

import com.tj.test.sys.dao.QuestionMapper;
import com.tj.test.sys.po.Question;
import com.tj.test.sys.service.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class QuestionService implements IQuestionService {
    @Autowired
    private QuestionMapper mapper;

    @Override
    //查询所有题库信息
    public List<Question> selectAllQuestion() {
        List<Question> list=new ArrayList<>();
        if (!mapper.selectAllQuestion().isEmpty()){
            list=mapper.selectAllQuestion();
        }
        return list;
    }

    @Override
    //根据教师id查询题库信息
    public List<Question> selectQuestionById(int teacherid) {
        List<Question> list=new ArrayList<>();
        if (!mapper.selectQuestionById(teacherid).isEmpty()){
            list=mapper.selectQuestionById(teacherid);
        }
        return list;
    }

    @Override
    //插入题库信息
    public int insertQuestion(Question question) {
        int temp=0;
        /* 业务判断
         * （1）名称不能重复
         * （2）增加之前先查询*/
        try{
                temp=mapper.insertQuestion(question);

        }catch (Exception e){
            return -1;
        }
        return temp;
    }

    @Override
    //删除题库信息
    public int deleteQuestion(Question question) {
        int temp=0;
        try{
                temp=mapper.deleteQuestion(question);
        }catch (Exception e){
            return -1;
        }
        return temp;
    }

    @Override
    //修改题库信息
    public int updateQuestion(Question question) {
        int temp=0;
        try{
            temp=mapper.updateQuestion(question);
        }catch (Exception e){
            return -1;
        }
        return temp;
    }
}
